package testimplicit

import scalapackage.testfanxing.MyGirl

/**
  * Created by Germmy on 2018/4/8.
  */
object MyPreDef {
  implicit  def fileToRichFile(path:String)=new RichFile(path)

  /**
    * 法一
    * @param g
    * @return
    */
  //  implicit  def selectGirl=(g:MyGirl)=>new Ordered[MyGirl] {//这个地方如果不用=>,用另外一种方式看行不行
//    override def compare(that: MyGirl): Int = {
//      if(g.faceValue==that.faceValue){
//        that.age-g.age//这个必须反过来
//      }else{
//        g.faceValue - that.faceValue
//      }
//    }
//  }

  /**
    * 法二
    * @param g
    * @return
    */
  implicit  def selectGirl(g:MyGirl)=new Ordered[MyGirl] {//这个地方如果不用=>,用另外一种方式看行不行
    override def compare(that: MyGirl): Int = {
      if(g.faceValue==that.faceValue){
        that.age-g.age//这个必须反过来
      }else{
        g.faceValue - that.faceValue
      }
    }
  }




  implicit  object  OrderingGirl extends  Ordering[MyGirl]{
    override def compare(x: MyGirl, y: MyGirl): Int = {
      if(x.faceValue==y.faceValue){
        y.age-x.age
      }else{
        x.faceValue-y.faceValue
      }
    }
  }




}
